//
//  ViewController.m
//  夜间模式
//
//  Created by Burn on 2018/10/19.
//  Copyright © 2018年 buren. All rights reserved.
//

#import "ViewController.h"
#import "ThemeManager.h"
#import "UIButton+Theme.h"
#import "UIView+Theme.h"
#import "ThemeManager.h"
#import "UITabBarItem+Theme.h"


@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
    btn.frame = CGRectMake(100, 100, 100, 50);
    [btn nightTextType:ThemeTypeRed];
    [btn setTitle:@"按钮文字" forState:UIControlStateNormal];
    [self.view addSubview:btn];
    
    
    
    
    UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(150, 300, 200, 50)];
    
    [label nightWithType:ThemeTypeBlack];
    label.text = @"夜间模式文字颜色测试观察";
    label.numberOfLines = 0;
    [self.view addSubview:label];
    
    
    
    UISwitch *sw = [[UISwitch alloc]initWithFrame:CGRectMake(200, 200, 50, 35)];
    sw.onTintColor = [UIColor orangeColor];
    sw.thumbTintColor = [UIColor redColor];
    
    [sw addTarget:self action:@selector(changeTheme) forControlEvents:UIControlEventValueChanged];
    [self.view addSubview:sw];
    
    [self.view nightWithType:ThemeTypeNormal];
    
    [self.navigationController.navigationBar nightWithType:ThemeTypeNormal];
    [self.navigationController.tabBarItem nightWithType:ThemeTypeBlack];
    [self.navigationController.tabBarController.tabBar nightWithType:ThemeTypeRed];
    self.navigationItem.title = @"观察文字";
    
    UITextField *field = [[UITextField alloc]initWithFrame:CGRectMake(20, 400, 200, 40)];
    field.borderStyle = UITextBorderStyleRoundedRect;
    [field nightWithType:ThemeTypeRed];
    [self.view addSubview:field];
}

- (void)changeTheme{
    [ThemeManager shareInstance].night = ![ThemeManager shareInstance].isNight;
    
    [[NSUserDefaults standardUserDefaults] setBool:[ThemeManager shareInstance].isNight forKey:@"THEME"];
    [[NSUserDefaults standardUserDefaults]synchronize];
    [[NSNotificationCenter defaultCenter]postNotificationName:@"CHANGECOLOR" object:nil];
}

- (void)dealloc {
    [[NSNotificationCenter defaultCenter]removeObserver:self];
}


@end
